/**
 * @ClassName Customer
 * @Description TODO
 * @Author Li
 * @Date 2022/8/9 16:10
 * @ModifyDate 2022/8/9 16:10
 * @Version 1.0
 */
public class Customer extends Thread {
    private Coffee coffee;

    public Customer(Coffee coffee) {
        this.coffee = coffee;
    }

    @Override
    public void run() {
        // 顾客永远存在
        while (true) {
            synchronized (coffee) {
                // 如果咖啡不存在则进入等待状态
                if (coffee.state == false) {
                    try {
                        coffee.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                // 咖啡已经做好了
                System.out.println("顾客开始喝：" + coffee.capacity + coffee.sugar + "咖啡！");
                System.out.println("顾客把咖啡喝完了！");
                coffee.state = false; // 标记咖啡已经喝完，不存在了
                coffee.notify(); // 唤醒咖啡机线程
                System.out.println("========================================="); // 华丽的分割线
            }
        }
    }
}
